<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jquery-3.6.0.min.js"></script>
    <style>
        table {
            width: 500px;
            margin: 20px auto;
            text-align: center;
            padding: 0px;
        }
        
        #foot {
            width: 500px;
            margin: 3px auto;
        }
        
        #foot div {
            width: 200px;
            float: right;
        }
        
        thead {
            background-color: cornflowerblue;
        }
        
        table,
        td,
        th {
            padding: 0px;
            border-collapse: collapse;
            padding: 5px 3px;
            height: 20px;
            line-height: 20px;
            border-bottom: 1px solid #777;
        }
        
        .bgeven {
            background-color: rgba(35, 196, 129, 0.473);
        }
        
        .bgodd {
            background-color: beige;
        }
    </style>
</head>

<body>


    <table>
        <thead>
            <tr>
                <td>
                    <input type="checkbox" name="all" id="all">
                </td>
                <td>序号</td>
                <td>姓名</td>
                <td>年龄</td>
                <td>成绩</td>
                <td>
                    操作
                </td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    <input type="checkbox" name="item" id="" value="">
                </td>

                <td>1</td>
                <td>张三</td>
                <td>20</td>
                <td>90.5</td>
                <td>
                    <a href="javascript:void(0);">删除</a>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="checkbox" name="item" id="" value="">
                </td>

                <td>2</td>
                <td>李四</td>
                <td>21</td>
                <td>89</td>
                <td>
                    <a href="javascript:void(0)">删除</a>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="checkbox" name="item" id="" value="">
                </td>

                <td>3</td>
                <td>王五</td>
                <td>20</td>
                <td>60</td>
                <td>
                    <a href="javascript:void(0);">删除</a>
                </td>
            </tr>

            <tr>
                <td>
                    <input type="checkbox" name="item" id="" value="">
                </td>

                <td>4</td>
                <td>王刘</td>
                <td>15</td>
                <td>14</td>
                <td>
                    <a href="javascript:void(0);">删除</a>
                </td>
            </tr>
        </tbody>

    </table>
    <div id="foot">
        <button>反选</button>
        <button id="del">删除选中</button>
        <div id="price">
            <span>总分</span>
            <span id="total">0.0</span>
        </div>

    </div>
    <script>
        $(function() {
            $("#all").change(function() {
                $("input").prop("checked", $("#all").prop("checked"))
                total();
            })

            function allcheck() {
                if ($("tbody input:checked").length == $("tbody input").length) {
                    $("#all").prop("checked", true);
                } else {
                    $("#all").prop("checked", false);
                }
                total();
            }

            function total() {
                var sum = 0;
                $("tbody input").each(function(i, ele) {
                    if ($(ele).prop("checked") == true) {
                        sum += parseFloat($(this).parent().nextAll().eq(3).html());
                    }
                })
                $("#total").html(sum);
            }
            $("tbody input").change(function() {
                allcheck();
            })
            $("button").eq(0).click(function() {
                $("tbody input").prop("checked", !$("tbody input").prop("checked"));
                allcheck();
            })
            $("#del").click(function() {
                $("tbody input").each(function(i, ele) {
                    if ($(ele).prop("checked") == true) {
                        $(this).parent().parent().remove();
                    }
                })
                allcheck();
            })
            $("a").click(function() {
                $(this).parent().parent().remove();
                allcheck();
            })
        })
    </script>

</body>

<script>
</script>

</html>